import 'package:flutter/material.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/common/system_address_item.dart';
import 'package:xinxuan/controllers/my_controller/address_controller/address_city_controller.dart';
import 'package:xinxuan/controllers/my_controller/address_controller/address_controller.dart';
import 'package:get/get.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:xinxuan/utils/color_util.dart';

class AddressCity extends StatelessWidget {

  final AddressController addressController = Get.find();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarUtil(
        title: '选择市',
        backgroundColor: pageBgColor,
      ),
      body: GetBuilder<AddressCityController>(
        init: AddressCityController(),
        builder: (controller) {
          return ScrollConfigurationCommon(child: ListView(
            children: controller.cityArr.map((item) {
              return SystemAddressItem(
                title: '${item.title}', 
                isSelected: addressController.providerItem.value.id == item.id, 
                onTap: () {
                  addressController.changeCityAddress(item);
                  Get.offNamed(
                    '${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.ADDRESS_LIST_PAGE}${AppRouters.ADD_EDIT_ADDRESS_PAGE}${AppRouters.ADDRESS_AREA}',
                    arguments: {
                      'id': item.id
                    }
                  );
                }
              );
            }).toList(),
          ));
        },
      ),
    );
  }
}